﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;

namespace SchoolManagementSystem.Forms
{
    public partial class frmEmailConfig : Form
    {
        public frmEmailConfig()
        {
            InitializeComponent();

            try
            {
                var user = RegisterService.RegisterServices.UserService.GetByID(Helper.ValueDefine.UserID) as CoreData.Users;

                txtemail.Text = user.Email;
                txtpass.Text = Helper.Security.DecryptString(user.PassEmail);
            }
            catch { }
        }

        private void simpleButton_ok_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtpass.Text))
            {
                MessageControl.ShowMessage("Vui lòng nhập mật khẩu", "Lỗi", MessageControl.Icon.Error);
                return;
            }
            if (String.IsNullOrEmpty(txtemail.Text))
            {
                MessageControl.ShowMessage("Vui lòng nhập email", "Lỗi", MessageControl.Icon.Error);
                return;
            }

            var user = RegisterService.RegisterServices.UserService.GetByID(Helper.ValueDefine.UserID) as CoreData.Users;

            user.Email = txtemail.Text;
            user.PassEmail = Helper.Security.EncryptString(txtpass.Text);
            RegisterService.RegisterServices.UserService.Save(user);
            MessageControl.ShowMessage("Đã lưu thông tin email của bạn", "", MessageControl.Icon.Success);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
